package com.ssm_basic.egweibo2.base.interceptor;

import com.ssm_basic.egweibo2.base.utils.JwtUtil;
import com.ssm_basic.egweibo2.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("LoginCheckInteceptor preHandle");
        String token = (String) request.getSession().getAttribute("user");
        try{
            Map<String, Object> claims = JwtUtil.parseToken(token);
            return true;
        } catch (Exception e) {
            throw new RuntimeException("请登录");
        }
    }
}
